package com.yinp.proapp.module.game.fourcolormap;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Region;

/**
 * Created by Administrator on 2019-10-21.
 */

public class ProvinceItem {
    public int selectColor = Color.WHITE;//地图快儿的颜色
    private Path path;
    public RectF provinceRectF = new RectF();
    public ProvinceItem(Path path) {
        this.path = path;
    }

    public void drawItem(Canvas canvas, Paint paint) {
        paint.setColor(selectColor);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawPath(path, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(2);
        paint.setColor(0xFFD0E8F4);
        canvas.drawPath(path, paint);
    }
    //判断点击屏幕的点在地图的哪一块儿
    public boolean isContains(float x, float y) {
        //注意注意这块是来判断点击位置的 主要知识点Region
        RectF rectF = new RectF();
        path.computeBounds(rectF, true);//获取path的边界
        Region region = new Region();
        region.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
        return region.contains((int) x, (int) y);
    }
}
